package game;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.Image;
import javax.microedition.m2g.ExternalResourceHandler;
import javax.microedition.m2g.ScalableImage;

/**
 * The Class ImageHandler is responsible for loading images for
 * the SVG-File.
 */
class ImageHandler implements ExternalResourceHandler {
	
	/* (non-Javadoc)
	 * @see javax.microedition.m2g.ExternalResourceHandler#requestResource(javax.microedition.m2g.ScalableImage, java.lang.String)
	 */
	public void requestResource(final ScalableImage scalableImage, final String URI) {
		final InputStream inputStream = Image.class.getResourceAsStream(URI);
		
		if (inputStream == null)
		System.out.println("Failed to load " + URI);
		
		try {
			scalableImage.requestCompleted(URI, inputStream);
		} catch (final IOException e) {
			e.printStackTrace();
		}
	}
}